﻿@page "/eqptable"
@attribute [TabItemOption(Text = "装备列表")]
@using BootstrapBlazor.Components
@using Microsoft.EntityFrameworkCore.Metadata.Internal
@using TrackSystem.Entities.Dtos.Equip;
@using TrackSystem.UI.Server.Units

<PageTitle>装备列表</PageTitle>

<Table TItem="EquipWithSensorsDto"
       IsPagination="true" PageItemsSource="@PageItemsSource"
       IsStriped="true" IsBordered="true" IsMultipleSelect="false" EditDialogIsDraggable="true"
       ShowToolbar="true" ShowExtendButtons="true"
       ShowSkeleton="true"
       IsExtendButtonsInRowHeader="true" ShowSearch="true"
       OnQueryAsync="@OnQueryAsync"
       OnSaveAsync="@OnSaveAsync"
       OnDeleteAsync="@OnDeleteAsync">

    <TableColumns>

        <TableColumn @bind-Field="@context.Id" Sortable="true" Width="50" />
        <TableColumn @bind-Field="@context.Name" Sortable="true" Width="200">
            <Template Context="value">
                <div class="d-flex">
                    @{
                        var row = value.Row;
                    }
                    <div class="ps-2">
                        <div>@value.Value</div>
                        <div class="user-demo-address">@row.Description</div>
                    </div>
                </div>
            </Template>
        </TableColumn>

        <TableColumn @bind-Field="@context.Sensors" Align="Alignment.Center">
                <Template Context="value">
                    <div class="ps-2">
                        <div>
                        @if (value.Row is { Sensors.Count: 0 })
                        {
                            <span class="badge bg-secondary">无传感器</span>
                        }
                        </div>
                        <div>
                        @foreach (var sensor in value.Row.Sensors)
                        {
                            <Button Text="@sensor.Name"
                                    ButtonStyle="ButtonStyle.Round"
                                    IsOutline="true"
                                    onclick="@(() => SkipToSensor(sensor.Id))"
                                    Color="Color.Primary">
                            </Button>
                        }
                        </div>
                    </div>
                </Template>
            </TableColumn>

        <TableColumn @bind-Field="@context.Logics" Align="Alignment.Center">
            <Template Context="value">
                <div class="ps-2">
                    <div>
                        @if (value.Row is { Logics.Count: 0 })
                        {
                            <span class="badge bg-secondary">无逻辑表达式</span>
                        }
                    </div>
                    <div>
                        @foreach (var logic in value.Row.Logics)
                        {
                            <Button Text="@logic.Name"
                                    ButtonStyle="ButtonStyle.Round"
                                    IsOutline="true"
                                    onclick="@(() => SkipToLogic(logic.Id))"
                                    Color="Color.Success">
                            </Button>
                        }
                    </div>
                </div>
            </Template>
        </TableColumn>

        <TableColumn @bind-Field="@context.Loops" Align="Alignment.Center">
            <Template Context="value">
                <div class="ps-2">
                    <div>
                        @if (value.Row is { Loops.Count: 0 })
                        {
                            <span class="badge bg-secondary">无控制回路</span>
                        }
                    </div>
                    <div>
                        @foreach (var loop in value.Row.Loops)
                        {
                            <Button Text="@loop.Name"
                                    ButtonStyle="ButtonStyle.Round"
                                    IsOutline="true"
                                    onclick="@(() => SkipToLoop(loop.Id))"
                                    Color="Color.Success">
                            </Button>

                        }
                    </div>
                </div>
            </Template>
        </TableColumn>

    </TableColumns>


    <EditTemplate>
        <div class="row g-3 form-inline">
            <div class="col-12 col-sm-6">
                <BootstrapInput @bind-Value="@context.Name"  maxlength="20"></BootstrapInput>
            </div>
            <div class="col-12 col-sm-6">
                <BootstrapInput @bind-Value="@context.Description" maxlength="50"></BootstrapInput>
            </div>
        </div>
    </EditTemplate>

</Table>

